<?php

class Rating extends CActiveRecord
{
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'ratings';
    }

    public function attributeLabels()
    {
        return array(
            'id'          => Yii::t('main', 'ID'),
            'user_id'     => Yii::t('main', 'User ID'),
            'rating'      => Yii::t('main', 'Rating'),
            'create_time' => Yii::t('main', 'Create time'),
            'update_time' => Yii::t('main', 'Update time'),
        );
    }

    public function behaviors()
    {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
            ),
        );
    }

    public function rules()
    {
        return array();
    }

    public function relations()
    {
        return array(
            'user' => array(self::BELONGS_TO, 'User', 'user_id'),
        );
    }

    public function scopes()
    {
        return array();
    }

    public function search()
    {
        $criteria = new CDbCriteria;

        $criteria->compare('user_id', $this->user_id);
        $criteria->compare('rating', $this->rating);
        $criteria->compare('create_time', $this->create_time, true);
        $criteria->compare('update_time', $this->update_time, true);

        $pagination = array('pageSize' => 20);
        $sort       = array('defaultOrder' => 't.create_time DESC');

        return new CActiveDataProvider(get_class($this), compact('criteria', 'sort', 'pagination'));
    }
}
